/**
 * 
 */
package client.gui.panels;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;

import controllers.ClosureController;
import controllers.ControllerIF;
import entities.User;

/**
 * @author Vodi
 *
 */
public class ClosurePanel extends JPanel implements PanelIF, ActionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * the panel's controller
	 */
	private ClosureController closureController;
	
	private JButton btnConfirm;
	private User connectedUser;
	
	public ClosurePanel(User connectedUser) {
		this.connectedUser = connectedUser;
		
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		
		Component verticalStrut = Box.createVerticalStrut(20);
		add(verticalStrut);
		
		JPanel panel = new JPanel();
		add(panel);
		panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
		
		JLabel lblDear = new JLabel("Dear ");
		lblDear.setFont(new Font("Times New Roman", Font.PLAIN, 16));
		panel.add(lblDear);
		
		JLabel userNameLabel = new JLabel(connectedUser.getFirstName());
		userNameLabel.setFont(new Font("Times New Roman", Font.PLAIN, 16));
		panel.add(userNameLabel);
		
		JLabel label = new JLabel(",");
		label.setFont(new Font("Times New Roman", Font.PLAIN, 16));
		panel.add(label);
		
		add(Box.createVerticalStrut(20));
		
		JPanel panel_1 = new JPanel();
		add(panel_1);
		panel_1.setLayout(new BoxLayout(panel_1, BoxLayout.X_AXIS));
		
		panel_1.add(Box.createHorizontalStrut(20));
		
		JTextArea txtrByClickingThe = new JTextArea();
		txtrByClickingThe.setWrapStyleWord(true);
		txtrByClickingThe.setMaximumSize(new Dimension(2147483647, 200));
		txtrByClickingThe.setEditable(false);
		txtrByClickingThe.setFont(new Font("Times New Roman", Font.PLAIN, 14));
		txtrByClickingThe.setLineWrap(true);
		txtrByClickingThe.setRows(5);
		txtrByClickingThe.setText("By clicking the \"confirm\" button you approve that you have read this document and agree with its handling process.");
		panel_1.add(txtrByClickingThe);
		
		panel_1.add(Box.createHorizontalStrut(20));
		
		add(Box.createVerticalStrut(20));
		
		JPanel panel_2 = new JPanel();
		add(panel_2);
		panel_2.setLayout(new BoxLayout(panel_2, BoxLayout.X_AXIS));
		
		panel_2.add(Box.createHorizontalGlue());
		
		btnConfirm = new JButton("Confirm");
		btnConfirm.addActionListener(this);
		panel_2.add(btnConfirm);
		
		panel_2.add(Box.createHorizontalStrut(20));
		
		add(Box.createVerticalStrut(20));
		
	}
	
	/* (non-Javadoc)
	 * @see client.gui.panels.PanelIF#setController(controllers.ControllerIF)
	 */
	@Override
	public void setController(ControllerIF cif) {
		this.closureController = (ClosureController) cif;
	}

	/**
	 * Get the connected user's ID number
	 * @return
	 */
	public Long getConnectedUserId() {
		return connectedUser.getId();
	}
	
	
	public void setPanelEnabled(boolean bool) {
		btnConfirm.setEnabled(bool);
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource().equals(btnConfirm)) {
			closureController.action();
		}
	}

}
